package com.example.admin.service.payConfig;

import com.lly835.bestpay.config.AliPayConfig;
import com.lly835.bestpay.config.WxPayConfig;
import com.lly835.bestpay.service.impl.BestPayServiceImpl;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "pay")
@Data
public class Config {
    private String wxAppId;
    private String wxMchId;
    private String wxMchKey;
    private String aliPayAppId;
    private String aliPayPrivateKey;
    private String aliPayPublicKey;
    private String backUrl;/*回调地址*/
    private String returnUrl;/*跳转地址*/
    /**
     * 将bestPayService加入到spring对象
     * bestPayService用来存储配置数据
     * @return
     */
    @Bean
    public BestPayServiceImpl setPayConfig() {
        /**
         * 微信支付  传入微信支付的配置对象
         */
        WxPayConfig wxPayConfig = new WxPayConfig();
        wxPayConfig.setAppId(this.wxAppId);/*appId*/
        wxPayConfig.setMchId(this.wxMchId);/*商户id*/
        wxPayConfig.setMchKey(this.wxMchKey);/*商户秘钥*/
        wxPayConfig.setNotifyUrl(this.backUrl); /*支付回调数据返回到这个url*/
        wxPayConfig.setReturnUrl(this.returnUrl);
        /**
         * 支付宝支付  传入支付宝的配置对象
         */
        AliPayConfig aliPayConfig = new AliPayConfig();
        aliPayConfig.setAppId(this.aliPayAppId);/*appId*/
        aliPayConfig.setPrivateKey(this.aliPayPrivateKey);/*商户应用的私钥*/
        aliPayConfig.setAliPayPublicKey(this.aliPayPublicKey);/*支付宝的公钥*/
        aliPayConfig.setNotifyUrl(this.backUrl); /*支付回调数据返回到这个url*/
        aliPayConfig.setReturnUrl(this.returnUrl);/*支付完成后跳转的页面*/

        BestPayServiceImpl bestPayService = new BestPayServiceImpl();
        bestPayService.setWxPayConfig(wxPayConfig);
        bestPayService.setAliPayConfig(aliPayConfig);
        return bestPayService;
    }
}
